package com.cybertooth.dbconvenience.query.columns;

import com.cybertooth.dbconvenience.query.core.SqlTransformer;
import com.cybertooth.dbconvenience.query.enums.SortDirection;

/**
 * <p></p>
 *
 * @author dnelson
 */
public class OrderByColumn implements SqlTransformer {

	// -----------------------------------------------------------------------Fields

	protected Column column;
	protected SortDirection sortDirection;

	// -----------------------------------------------------------------Constructors

	public OrderByColumn(Column column, SortDirection sortDirection) {
		this.column = column;
		this.sortDirection = sortDirection;
	}

	public OrderByColumn(Column column) {
		this.column = column;
		this.sortDirection = SortDirection.ASC;
	}

	// ---------------------------------------------------------------Public Methods

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toSql() {
		return new StringBuilder()
				.append(" ").append(this.column.toSql()).append(this.sortDirection.toSql().trim()).append(" ")
				.toString();
	}
}
